unit NetworkCommon;

// This unit is the information that both the server and the client must have

{$mode objfpc}{$H+}
interface


uses Classes, SysUtils,
     GLMisc,    //  the TGLCoordinates type for the position
     GLObjects  //  the GLSphere type for the construction
     ;

type

  Str50 = String[50];

  TMessageType = (mtSphereInfo,mtBool,mtOwn,mtPick);

  TSphereInfo = packed record
    mt : TMessageType;
    Name : Str50;
    Position : TGLCoordinates;
  end;

  TBoolVarType = (btPeek, btPeeking, btReset, btDrop);

  TBoolMessage = packed record
    mt : TMessageType;
    Variable : TBoolVarType;
    Value : boolean;
  end;


  // Own and making your actual pick uses the same type
  TOwnMessage = packed record
    mt : TMessageType;
    Name : Str50;
  end;

var

  TSphereInfoSize  : integer;
  TBoolMessageSize : integer;
  TOwnMessageSize  : integer;



implementation




(*
// TSphereInfo
constructor TSphereInfo.create(aSphere:TGLSphere);
begin
  Position := aSphere.position;
  Name := aSphere.Name;
  Size := Sizeof(size) + Length(Name) + Sizeof(Position) + Sizeof(mt);
  mt := mtSphereInfo;
end;

constructor TSphereInfo.Create(aSize:integer;aName:String;aPosition:TGLCoordinates);
begin
  Size := aSize;
  Name := aName;
  Position := aPosition;
  mt := mtSphereInfo;
end;


// TBoolMessage

constructor TBoolMessage.create(aVariable : TBoolVarType; aValue:boolean);
begin
  Variable := aVariable;
  Value := aValue;
  Size := Sizeof(Size) + Sizeof(mt) + Sizeof(Variable) + Sizeof(Value);
  mt := mtBool;
end;

constructor TBoolMessage.create(aSize: integer; aVariable : TBoolVarType; aValue:boolean);
begin
  Size := aSize;
  Variable := aVariable;
  Value := aValue;
  mt := mtBool;
end;


// TOwnMessage
constructor TOwnMessage.Create(aSphere:TGLSphere);
begin
  Name := aSphere.Name;
  Size := Sizeof(Size) + Length(Name) + Sizeof(mt);
  mt := mtOwn;
end;


constructor TOwnMessage.Create(aName:String);
begin
  Name := aName;
  Size := sizeof(size)+length(name)+sizeof(mt);
  mt := mtOwn;
end;*)


end.

